package com.credithc.signature.common.utils;

import freemarker.template.Configuration;
import lombok.extern.slf4j.Slf4j;

import java.io.File;

/**
 * 描述：Freemarker Configuration工厂类<br/>
 * 作者：sunyang
 * 创建：2019/6/5 10:49
 * 版本：v1.0.0<br/>
 */
@Slf4j
public class FreemarkerConfiguration {

	private static Configuration config = null;

	private static final String SNAP_TEMPLATE_PATH = FreemarkerConfiguration.class.getResource("/").getPath().
			replaceAll("%20", " ") + "snapTemplate/";

	static {
		try {
			File file = new File(SNAP_TEMPLATE_PATH);
			if (!file.exists()){
				file.mkdirs();
			}
			config = new Configuration(Configuration.VERSION_2_3_23);
			config.setDirectoryForTemplateLoading(file);
		} catch (Exception e) {
			log.error("初始化FreemarkerConfiguration失败", e);
		}
	}

	public static Configuration getConfiguation() {
		return config;
	}

	public static String getFreemarkerFileDirPath() {
		return SNAP_TEMPLATE_PATH;
	}

}